﻿using System;
using System.Collections.Generic;
using System.Linq;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

using RFEngine;
using RFEngine.Entities;
using RFEngine.Graphics.Interfaces;

namespace RFEngine.Graphics
{
    public class PositionedObject : IEntity, IPositionable, IRotateable
    {
        #region Fields

        private string _Name;
        private float _TimeCreated;

        protected Vector3 _Position;
        protected Vector3 _Rotation;
        protected Vector3 _RotationRate;
        protected Vector3 _Velocity;

        #endregion

        #region Properties

        /// <summary>
        /// Gets or Sets the Name for this Entity.
        /// </summary>
        public string Name
        {
            get { return _Name; }
            set { _Name = value; }
        }

        /// <summary>
        /// Gets the Time in seconds when this entity was created.
        /// </summary>
        public float TimeCreated
        {
            get { return _TimeCreated; }
        }

        /// <summary>
        /// Gets or Sets the position of this object in world space along the x-axis
        /// </summary>
        public virtual float X
        {
            get { return _Position.X; }
            set { _Position.X = value; }
        }

        /// <summary>
        /// Gets or Sets the rate at which this object moves along the x-axis in units per second.
        /// </summary>
        public virtual float XVelocity
        {
            get { return _Velocity.X; }
            set { _Velocity.X = value; }
        }

        /// <summary>
        /// Gets or Sets the rotation of this object around the x-axis in world space.
        /// </summary>
        public virtual float XRotation
        {
            get { return _Rotation.X; }
            set { _Rotation.X = value; }
        }

        /// <summary>
        /// Gets or Sets the rotation at which this object rotates around the x-axis in units per second.
        /// </summary>
        public virtual float XRotationRate
        {
            get { return _RotationRate.X; }
            set { _RotationRate.X = value; }
        }

        /// <summary>
        /// Gets or Sets the position of this object in world space along the y-axis
        /// </summary>
        public virtual float Y
        {
            get { return _Position.Y; }
            set { _Position.Y = value; }
        }

        /// <summary>
        /// Gets or Sets the rate at which this object moves along the y-axis in units per second.
        /// </summary>
        public virtual float YVelocity
        {
            get { return _Velocity.Y; }
            set { _Velocity.Y = value; }
        }

        /// <summary>
        /// Gets or Sets the rotation of this object around the y-axis in world space.
        /// </summary>
        public virtual float YRotation
        {
            get { return _Rotation.Y; }
            set { _Rotation.Y = value; }
        }

        /// <summary>
        /// Gets or Sets the rotation at which this object rotates around the y-axis in units per second.
        /// </summary>
        public virtual float YRotationRate
        {
            get { return _RotationRate.Y; }
            set { _RotationRate.Y = value; }
        }

        /// <summary>
        /// Gets or Sets the position of this object in world space along the z-axis
        /// </summary>
        public virtual float Z
        {
            get { return _Position.Z; }
            set { _Position.Z = value; }
        }

        /// <summary>
        /// Gets or Sets the rate at which this object moves along the z-axis in units per second.
        /// </summary>
        public virtual float ZVelocity
        {
            get { return _Velocity.Z; }
            set { _Velocity.Z = value; }
        }

        /// <summary>
        /// Gets or Sets the rotation of this object around the z-axis in world space.
        /// </summary>
        public virtual float ZRotation
        {
            get { return _Rotation.Z; }
            set { _Rotation.Z = value; }
        }

        /// <summary>
        /// Gets or Sets the rotation at which this object rotates around the z-axis in units per second.
        /// </summary>
        public virtual float ZRotationRate
        {
            get { return _RotationRate.Z; }
            set { _RotationRate.Z = value; }
        }

        /// <summary>
        /// Gets the position of this object in world space.
        /// </summary>
        public virtual Vector3 Position
        {
            get { return _Position; }
        }

        /// <summary>
        /// Gets the velocity of this object in units per second.
        /// </summary>
        public virtual Vector3 Velocity
        {
            get { return _Velocity; }
        }

        /// <summary>
        /// Gets the rotation of this object in degrees.
        /// </summary>
        public virtual Vector3 Rotation
        {
            get { return _Rotation; }
        }

        #endregion

        #region Methods

        #region Constructor(s)

        /// <summary>
        /// Constructs a new instance of this object.
        /// </summary>
        public PositionedObject() 
        {
            _TimeCreated = TimeManager.ElapsedGameTime;
        }

        #endregion

        /// <summary>
        /// Method for setting the rotation of this object.
        /// </summary>
        /// <param name="xRotation">The rotation of this object around the x-axis.</param>
        /// <param name="yRotation">The rotation of this object around the x-axis.</param>
        /// <param name="zRotation">The rotation of this object around the x-axis.</param>
        public void SetRotation(float xRotation, float yRotation, float zRotation)
        {
            _Rotation.X = xRotation;
            _Rotation.Y = yRotation;
            _Rotation.Z = zRotation;
        }

        /// <summary>
        /// Method for setting the rotation of this object.
        /// </summary>
        /// <param name="rotation">The rotation to set this object to.</param>
        public void SetRotation(ref Vector3 rotation)
        {
            _Rotation = rotation;
        }

        /// <summary>
        /// Method for setting the position of this object.
        /// </summary>
        /// <param name="x">The position of this object along the x-axis in world space.</param>
        /// <param name="y">The position of this object along the x-axis in world space.</param>
        /// <param name="z">The position of this object along the x-axis in world space.</param>
        public virtual void SetPosition(float x, float y, float z)
        {
            _Position.X = x;
            _Position.Y = y;
            _Position.Z = z;
        }

        /// <summary>
        /// Method for setting the position of this object.
        /// </summary>
        /// <param name="position">The position to set this object in world space.</param>
        public virtual void SetPosition(ref Vector3 position)
        {
            _Position = position;
        }

        #endregion
    }
}
